babl: do not use model.data for storing original model backpointer
authorØyvind Kolås <pippin@gimp.org>
Wed, 4 Oct 2017 14:16:45 +0000 (16:16 +0200)
committerØyvind Kolås <pippin@gimp.org>
Wed, 4 Oct 2017 14:17:21 +0000 (16:17 +0200)
Fixing bug #788471

babl/babl-conversion.c
babl/babl-fish-path.c
babl/babl-fish.c
babl/babl-model.c
babl/babl-model.h

index b08f835af9bd0bb43f7a78138a14b85f22ef0d80..75e5c93b1472dbc4d21f0f7fa5bb82aaae849f1f 100644 (file)
@@ -29,7 +29,7 @@
 static int model_is_rgba (const Babl *model)
 {
   const Babl *RGBA = babl_model_from_id (BABL_RGBA);
-  if (model == RGBA || model->model.data == RGBA)
+  if (model == RGBA || model->model.model == RGBA)
     return 1;
   return 0;
 }
index 2a71464b9b608ea1896f39ec1da487d9e2ea87a3..6a1e1941e5b6284fa62acc4f945348b92e1490bc 100644 (file)
@@ -330,7 +330,9 @@ alias_conversion (Babl *babl,
   BablSpace *space = user_data;
 
   if ((conv->source->class_type == BABL_FORMAT) &&
-      (conv->destination->class_type == BABL_FORMAT))
+      (conv->destination->class_type == BABL_FORMAT) &&
+      (!babl_format_is_palette (conv->source)) &&
+      (!babl_format_is_palette (conv->destination)))
   {
     if ((conv->source->format.space == (void*)babl_space ("sRGB")) &&
         (conv->destination->format.space == babl_space ("sRGB")))
index 6e22f899b9a6c8d6d9c35f9e59f2d9720fc992b3..749b075c2930ec74fb33482677a66594d2de72de 100644 (file)
@@ -126,8 +126,8 @@ babl_conversion_find (const void *source,
 
   if (BABL (source)->class_type == BABL_MODEL)
   {
-     const Babl *srgb_source = BABL (source)->model.data ? BABL (source)->model.data:source;
-     const Babl *srgb_destination = BABL (destination)->model.data ? BABL (destination)->model.data:destination;
+     const Babl *srgb_source = BABL (source)->model.model ? BABL (source)->model.model:source;
+     const Babl *srgb_destination = BABL (destination)->model.model ? BABL (destination)->model.model:destination;
      Babl *reference = babl_conversion_find (srgb_source, srgb_destination);
 
   /* when conversions are sought between models, with non-sRGB chromaticities,
index 0e28a1758b56a17e3316ff9a96f7626fc6823061..d553aca73ce723a03290057fbd42240894ee6499 100644 (file)
@@ -72,6 +72,7 @@ model_new (const char     *name,
   babl->model.components = components;
   babl->model.space      = space;
   babl->model.data       = NULL;
+  babl->model.model      = NULL;
   strcpy (babl->instance.name, name);
   memcpy (babl->model.component, component, sizeof (BablComponent *) * components);
 
@@ -373,17 +374,22 @@ babl_remodel_with_space (const Babl *model, const Babl *space)
 {
   Babl *ret;
   int i;
+  assert (BABL_IS_BABL (model));
 
   if (model->model.space == space)
     return (void*)model;
 
+  assert (BABL_IS_BABL (model));
+
   /* get back to the sRGB model if we are in a COW clone of it  */
-  if (model->model.data)
-    model = (void*)model->model.data;
+  if (model->model.model)
+    model = (void*)model->model.model;
+
+  assert (BABL_IS_BABL (model));
 
   for (i = 0; i < babl_n_remodels; i++)
   {
-    if (babl_remodels[i]->model.data == model &&
+    if (babl_remodels[i]->model.model == model &&
         babl_remodels[i]->model.space == space)
           return babl_remodels[i];
   }
@@ -391,7 +397,7 @@ babl_remodel_with_space (const Babl *model, const Babl *space)
   ret = babl_calloc (sizeof (BablModel), 1);
   memcpy (ret, model, sizeof (BablModel));
   ret->model.space = space;
-  ret->model.data = (void*)model; /* use the data as a backpointer to original model */
+  ret->model.model = (void*)model; /* use the data as a backpointer to original model */
   return babl_remodels[babl_n_remodels++] = ret;
   return (Babl*)ret;
 }
index 2395005bf40b62d6d79165d64c9f4e3fb83e03e6..96ff903633172b4a2676e082c0cb1cafbca60643 100644 (file)
@@ -29,9 +29,8 @@ typedef struct
   BablComponent   **component;
   BablType        **type; /*< must be doubles,
                               used here for convenience in code */
-  void             *data; /*  used for palette - and maybe back pointer
-                              to actual model?
-                           */
+  void             *data;    /* user-data, used for palette */
+  void             *model;   /* back pointer to model with sRGB space */
   const Babl       *space;
 } BablModel;